//-----------------------------------------------------------------------
// <copyright file="a_User_CareerDAOBase.cs" company="AACECOM">
//     Copyright (c) AACECOM. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using Microsoft.Practices.EnterpriseLibrary.Data;
using ThoiTrang.Entities;

namespace ThoiTrang.Data
{    
    public abstract class a_User_CareerDAOBase
    {
        #region Common methods
        public virtual a_User_Career Createa_User_CareerFromReader(IDataReader reader)
        {
            a_User_Career item = new a_User_Career();
            try
            {
                if (!reader.IsDBNull(reader.GetOrdinal("CarID"))) item.CarID = (int)reader["CarID"];
                if (!reader.IsDBNull(reader.GetOrdinal("CarNameVN"))) item.CarNameVN = (string)reader["CarNameVN"];
                if (!reader.IsDBNull(reader.GetOrdinal("CarNameEN"))) item.CarNameEN = (string)reader["CarNameEN"];
            }
            catch (Exception ex)
            {                
                throw ex;
            }
            return item;
        }
        #endregion
        
        #region Createa_User_Career methods
            
        public virtual void Createa_User_Career(a_User_Career a_User_Career)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_User_Career_ins");
                
                database.AddInParameter(dbCommand, "@CarNameVN", DbType.String, a_User_Career.CarNameVN);
                database.AddInParameter(dbCommand, "@CarNameEN", DbType.AnsiString, a_User_Career.CarNameEN);
                database.AddOutParameter(dbCommand, "@CarID", DbType.Int32, 0);
                
                database.ExecuteNonQuery(dbCommand);
                a_User_Career.CarID = (int)database.GetParameterValue(dbCommand, "@CarID");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        #endregion

        #region Updatea_User_Career methods
        
        public virtual void Updatea_User_Career(a_User_Career a_User_Career)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_User_Career_upd");            
                
                database.AddInParameter(dbCommand, "@CarID", DbType.Int32, a_User_Career.CarID);
                database.AddInParameter(dbCommand, "@CarNameVN", DbType.String, a_User_Career.CarNameVN);
                database.AddInParameter(dbCommand, "@CarNameEN", DbType.AnsiString, a_User_Career.CarNameEN);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }
        
        #endregion

        #region Deletea_User_Career methods
        public virtual void Deletea_User_Career(int carID)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_User_Career_del");
                
                database.AddInParameter(dbCommand, "@CarID", DbType.Int32, carID);
                
                database.ExecuteNonQuery(dbCommand);
            }
            catch (Exception ex)
            {
               throw ex;
            }
        }

        #endregion

        #region Geta_User_Career methods
        
        public virtual a_User_Career Geta_User_Career(int carID)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_User_Career_sel");
                
                database.AddInParameter(dbCommand, "@CarID", DbType.Int32, carID);
                
                a_User_Career a_User_Career =  null;
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    if (reader.Read())
                    {
                        a_User_Career = Createa_User_CareerFromReader(reader);
                        reader.Close();
                    }
                }
                return a_User_Career;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        #endregion

        #region Geta_User_CareerList methods
        public virtual a_User_CareerCollection Geta_User_CareerList(a_User_CareerColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {            
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_User_Career_selList");
                
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);
                
                a_User_CareerCollection a_User_CareerCollection = new a_User_CareerCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_User_Career a_User_Career = Createa_User_CareerFromReader(reader);
                        a_User_CareerCollection.Add(a_User_Career);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_User_CareerCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        
        public virtual a_User_CareerCollection Geta_User_CareerList(a_User_CareerColumns orderBy, OrderDirection orderDirection)
        {            
            int totalRecords = 0;
            return Geta_User_CareerList(orderBy, orderDirection, 0, 0, out totalRecords);
        }
        
        #endregion

        #region Geta_User_CareerList_alphabet methods
        public virtual a_User_CareerCollection Geta_User_CareerList_alphabet(string mychar, a_User_CareerColumns orderBy, OrderDirection orderDirection, int page, int pageSize, out int totalRecords)
        {
            try
            {
                Database database = DatabaseFactory.CreateDatabase();
                DbCommand dbCommand = database.GetStoredProcCommand("a_User_Career_selList_alphabet");
                database.AddInParameter(dbCommand, "@Mychar", DbType.AnsiString, mychar);
                database.AddInParameter(dbCommand, "@OrderBy", DbType.AnsiString, orderBy.ToString());
                database.AddInParameter(dbCommand, "@OrderDirection", DbType.AnsiString, orderDirection.ToString());
                database.AddInParameter(dbCommand, "@Page", DbType.Int32, page);
                database.AddInParameter(dbCommand, "@PageSize", DbType.Int32, pageSize);
                database.AddOutParameter(dbCommand, "@TotalRecords", DbType.Int32, 4);

                a_User_CareerCollection a_User_CareerCollection = new a_User_CareerCollection();
                using (IDataReader reader = database.ExecuteReader(dbCommand))
                {
                    while (reader.Read())
                    {
                        a_User_Career a_User_Career = Createa_User_CareerFromReader(reader);
                        a_User_CareerCollection.Add(a_User_Career);
                    }
                    reader.Close();
                }
                totalRecords = (int)database.GetParameterValue(dbCommand, "@TotalRecords");
                return a_User_CareerCollection;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public virtual a_User_CareerCollection Geta_User_CareerList_alphabet(string mychar, a_User_CareerColumns orderBy, OrderDirection orderDirection)
        {
            int totalRecords = 0;
            return Geta_User_CareerList_alphabet(mychar, orderBy, orderDirection, 0, 0, out totalRecords);
        }

        #endregion
    }
}